package com.ewanghuiju.app.ui.pintuan.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.test.bean.PintuanClassifyRightBean;
import com.ewanghuiju.app.test.bean.PintuanEjClassifyRightBean;
import com.ewanghuiju.app.ui.pintuan.activity.PintuanHotActivity;
import com.ewanghuiju.app.util.StartActivityUtil;

import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class PintuanClassifyRightAdapter extends BaseQuickAdapter<PintuanClassifyRightBean, BaseViewHolder> {
    public PintuanClassifyRightAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, PintuanClassifyRightBean item) {
        if (item.getThree() == null || item.getThree().size() == 0) {
            CardView cv = helper.getView(R.id.card_view);
            cv.setVisibility(View.GONE);
            return;
        }
        helper.setText(R.id.header, item.getName());
        RecyclerView recyclerView = helper.getView(R.id.rv_ej_classify);

        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 3));

        PintuanEjClassifyRightAdapter adapter = new PintuanEjClassifyRightAdapter(R.layout.item_pintuan_ejclassify_right);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                PintuanEjClassifyRightBean pintuanEjClassifyRightBean = (PintuanEjClassifyRightBean) adapter.getItem(position);
                new StartActivityUtil(mContext, PintuanHotActivity.class).putExtra(Constants.PINTUAN_SHOP_TYPE,
                        2).putExtra(Constants.PINTUAN_SHOP,
                        pintuanEjClassifyRightBean.getId())
                        .putExtra(Constants.PINTUAN_SHOP_TITLE,
                                pintuanEjClassifyRightBean.getName())
                        .startActivity(true);
            }
        });
        recyclerView.setAdapter(adapter);
        adapter.setNewData(item.getThree());
    }
}
